package com.matrix.index.ui.home

import android.view.View
import android.view.ViewAnimationUtils
import androidx.activity.enableEdgeToEdge
import com.alibaba.android.arouter.facade.annotation.Route
import com.matrix.basecore.base.BaseActivity
import com.matrix.basecore.constant.Constant
import com.matrix.index.databinding.ActivityJokePreviewBinding
import kotlin.math.max

@Route(path = Constant.ARouterPath.JokePreviewActivityPath)
class JokePreviewActivity : BaseActivity<ActivityJokePreviewBinding>() {

    override fun getViewBinding(): ActivityJokePreviewBinding {
        return ActivityJokePreviewBinding.inflate(layoutInflater)
    }

    override fun initView() {
        enableEdgeToEdge()
        mViewBinding.tvContent.let {
            it.post {
                var content = intent.getStringExtra(Constant.ARouterString.CONTENT)
                it.text = content
                startAnimation(it)
            }
        }
    }

    private fun startAnimation(view: View) {
        view.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
            val animationTop = ViewAnimationUtils.createCircularReveal(
                view, view.width / 2,
                view.height / 2, 0f,
                max(
                    (view.width / 2).toDouble(),
                    (view.height / 2).toDouble()
                ).toFloat()
            )
            animationTop.setDuration(500)
            animationTop.start()
        }
    }

    override fun initListener() {
        mViewBinding.includeTitle.ivBack.setOnClickListener {
            finish()
        }
    }
}